#include "filter.h"

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;

int main()
{
    cv::Mat img = cv::imread("/home/lin/图片/007.png");
    cv::resize(img,img,cv::Size(640,480));
    cv::Mat gkernel = ex2::generate_gaussian_kernel(2,3);//高斯核
    cv::Mat se = cv::Mat(5,5,CV_32FC1,cv::Scalar(1.0/25.0));

    cv::Mat gray_img,thre_img;
    cv::cvtColor(img,gray_img,cv::COLOR_BGR2GRAY);
    cv::threshold(gray_img,thre_img,125.0,255,cv::THRESH_BINARY);
    auto g_img = conv2d(gray_img,se);

    cv::Mat erode_img,dilate_img;
    ex2::Erode(thre_img,erode_img,se);
    ex2::Dilate(thre_img,dilate_img,se);

    auto diff = erode_img - dilate_img;


    cv::Mat show_gaussian,show_erode,show_dilate;
    g_img.convertTo(show_gaussian,CV_8U,1);
    erode_img.convertTo(show_erode,CV_8U,1);
    dilate_img.convertTo(show_dilate,CV_8U,1);
    while (true)
    {
        cv::imshow("gray",gray_img);
        cv::imshow("filter",show_gaussian);
        cv::imshow("threshold",thre_img);
        cv::imshow("erode",show_erode);
        cv::imshow("dilate",show_dilate);
        char q = cv::waitKey(10);
        if (q==27){
            break;
        }
    }
    cv::destroyAllWindows();
}